package com.woniuxy.oa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.woniuxy.oa.entity.AddressMsg;
import com.woniuxy.oa.entity.EmployeeMsg;
import com.woniuxy.oa.entity.PageMsg;
import com.woniuxy.oa.mapper.AddressMsgMapper;
import com.woniuxy.oa.service.AddressService;

@Service("AddressService")
public class AddressServiceImpl implements AddressService {
	
	@Autowired
	AddressMsgMapper addressMsgMapper;

	//条件查询员工信息
	@Override
	public PageMsg selectEmployeeMsgByCondition(EmployeeMsg employeeMsg, int pageIndex, int pageSize) {
		int recordBegin=(pageIndex-1)*10;
		List<EmployeeMsg> employees = addressMsgMapper.selectAddressByCondition(employeeMsg, recordBegin, pageSize);
		//将查询出来的结果封装为一个页信息对象
		
		int recordTotal=addressMsgMapper.selectCountRecordByCondition(employeeMsg);
		PageMsg pageMsg=new PageMsg();
		pageMsg.setEmployeeMsgs(employees);
		pageMsg.setPageIndex(pageIndex);
		pageMsg.setPageSize(pageSize);
		pageMsg.setRecordTotal(recordTotal);
		pageMsg.setPageBeginAndPageEnd();
		
		return pageMsg;
	}

	//修改员工地址信息
	@Transactional
	@Override
	public void modifyAddressMsg(AddressMsg addressMsg) {
		addressMsgMapper.modifyAddress(addressMsg);
		addressMsgMapper.modifyUserName(addressMsg.getE_id(), addressMsg.getUsername());
	}

	
	//删除员工信息
	@Transactional
	@Override
	public void deleteAddressMsg(int id) {
		addressMsgMapper.deleteAddress(id);
		addressMsgMapper.deleteUser(id);
		
	}

	//查询所有员工Id
	@Override
	public List<Integer> selectAllId() {
		return addressMsgMapper.selectAllId();
	}

	

	

}
